
import { BuiltInData } from '../../Config/tableOptions'
import { BaseFormButton } from '../../Utils/TableButton'
import { commonTableList } from '../../Config/tableCommon'

const { port } = window.location


// TODO 入参 uuid, url, ProTableEvent, ClientData, Permission, actionRef
const ProjectCommon = async ({ url, ProTableEvent, actionRef }) => {
    const get = `get${url}`
    const pos = `pos${url}`
    const put = `put${url}`
    const del = `del${url}`

    const initialValues = {
        isEnabled: 1,
        isDebug: 0,
        isScan: 0,
        loginMethod: 0,
        bearer: 'Bearer'
    }

    const options = () => {
        return ([
            <BaseFormButton
                key='add'
                event='NewAdd'
                ProTableEvent={ProTableEvent}
                type="primary"
                icon="add"
                title="新增"
                data={{ params: { pos, put, initialValues, columns } }}
            />
        ])
    }

    const columns = [
        commonTableList.uuid,
        { ...commonTableList.tableName, title: '项目简称', width: 200 },
        { ...commonTableList.fullName, title: '项目全称', width: 400 },
        {
            dataIndex: 'loginMethod',
            title: '登录方式',
            valueType: 'select',
            valueEnum: BuiltInData.LoginMethod,
            ellipsis: true,
            rules: true,
            width: 200,
            hideInSearch: true
        },
        {
            dataIndex: 'client_Id',
            title: '登录ID',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
        },
        {
            dataIndex: 'client_Secret',
            title: '登录Secret',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
        },
        {
            dataIndex: 'grant_Type',
            title: '登录Type',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 200,
        },
        {
            dataIndex: 'webUrl',
            title: '项目地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 400,
            hideInSearch: true
        },
        {
            dataIndex: 'authUrl',
            title: '授权地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 400,
            hideInSearch: true
        },
        {
            dataIndex: 'apiUrl',
            title: '接口地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 400,
            hideInSearch: true
        },
        {
            dataIndex: 'imageUrl',
            title: '图床地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 400,
            hideInSearch: true
        },
        {
            dataIndex: 'weChatApiUrl',
            title: '小程序接口地址',
            valueType: 'input',
            ellipsis: true,
            rules: true,
            width: 400,
            hideInSearch: true
        },
        {
            dataIndex: 'address',
            title: '项目所在地',
            valueType: 'input',
            ellipsis: true,
            width: 200,
        },
        {
            dataIndex: 'projectTypeUuid',
            title: '项目类型',
            valueType: 'input',
            ellipsis: true,
            width: 200,
        },
        {
            dataIndex: 'login',
            title: '登录页面',
            valueType: 'input',
            ellipsis: true,
            width: 200,
            hideInSearch: true
        },
        {
            dataIndex: 'isScan',
            title: '扫码登录',
            valueType: 'select',
            valueEnum: BuiltInData.isEnabled,
            ellipsis: true,
            width: 200,
            hideInSearch: true,
            enumObject: true,
        },
        {
            dataIndex: 'isDebug',
            title: '开启debug',
            valueType: 'select',
            valueEnum: BuiltInData.isEnabled,
            ellipsis: true,
            width: 200,
            hideInSearch: true,
            enumObject: true,
        },
        {
            dataIndex: 'bearer',
            title: '认证方式',
            valueType: 'select',
            valueEnum: BuiltInData.BearerType,
            ellipsis: true,
            rules: true,
            width: 200,
            hideInSearch: true
        },

        commonTableList.code,
        commonTableList.sortId,
        commonTableList.isEnabled,
        commonTableList.remark,
        {
            title: '操作',
            valueType: 'systemOperation',
            fixed: 'right',
            width: 240,
            align: 'center',
            hideInSearch: true,
            hideInAdded: true,
            hideInModify: true,
            render: (_, record) => {
                const { uuid, webUrl } = record
                return [
                    <BaseFormButton
                        key='Modify'
                        event='Modify'
                        ProTableEvent={ProTableEvent}
                        title="修改"
                        data={{ params: { pos, put, initialValues, columns }, record }}
                    />,
                    <BaseFormButton
                        key='delete'
                        event='Delete'
                        ProTableEvent={ProTableEvent}
                        title="删除"
                        danger
                        data={{ url: del, path: [uuid], actionRef }}
                    />,
                    <BaseFormButton
                        key='A01'
                        event='NavTo'
                        ProTableEvent={ProTableEvent}
                        title="跳转"
                        data={{ url: port ? `http://${webUrl}:${port}` : webUrl }}
                    />,
                ]
            },
        },
    ]



    return {
        get,
        columns,
        params: { pageIndex: 1, pageSize: 1000 },
        options
    }
}

export default ProjectCommon